package com.cola.web.request;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

@WebServlet("/req3")
public class RequestDemo3 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1.解决post方法的中文乱码问题
//        request.setCharacterEncoding("UTF-8");
//        String username = request.getParameter("username");
//        System.out.println(username);


        // 2.解决get方法的中文乱码问题(post方法也可以)
        String username = request.getParameter("username");
        System.out.println("解决前："+username);
        username = new String(username.getBytes(StandardCharsets.ISO_8859_1));
        System.out.println("解决后："+username);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        this.doGet(request,response);
    }
}
